package net.opentsdb.plugin;

import com.stumbleupon.async.Deferred;
import net.opentsdb.core.TSDB;
import net.opentsdb.stats.StatsCollector;

public interface PluginOperator {

    /**
     * Called by TSDB to initialize the plugin
     * Implementations are responsible for setting up any IO they need as well
     * as starting any required background threads.
     * <b>Note:</b> Implementations should throw exceptions if they can't start
     * up properly. The TSD will then shutdown so the operator can fix the
     * problem. Please use IllegalArgumentException for configuration issues.
     * @param tsdb The parent TSDB object
     * @throws IllegalArgumentException if required configuration parameters are
     * missing
     * @throws RuntimeException if something else goes wrong
     */
    void initialize(final TSDB tsdb);

    /**
     * Called when the TSD is shutting down to gracefully flush any buffers or
     * close open connections.
     */
    Deferred<Object> shutdown();

    /**
     * Should return the version of this plugin in the format:
     * MAJOR.MINOR.MAINT, e.g. 2.0.1. The MAJOR version should match the major
     * version of OpenTSDB the plugin is meant to work with.
     * @return A version string used to log the loaded version
     */
    String version();

    /**
     * Called by the TSD when a request for statistics collection has come in. The
     * implementation may provide one or more statistics. If no statistics are
     * available for the implementation, simply stub the method.
     * @param collector The collector used for emitting statistics
     */
    void collectStats(final StatsCollector collector);
}
